<?php

class Validate {
	public static function blank($value) {
		return !preg_match('/[^\s]/', $value);
	}
	
    public static function min($value, $length) {
        $value_length = strlen($value);
        return $value_length >= $length;
    }

    public static function max($value, $length) {
        $value_length = strlen($value);
        return $value_length <= $length;
    }
	
	public static function exact($value, $size) {
		if (preg_match('/[^0-9]/', $size)) {
			return true;
		}
		return strlen(trim($value)) != $size;
	}
	
	public static function mail($value) {
		return preg_match('/^([a-z0-9\+_\-])(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $value);	
	}
	
	public static function alphanumeric($value) {
		return preg_match('/^[a-z\d_ ]{1,1000}$/i', $value);
	}
	
    public static function between($value, $min, $max) {
        if (!is_numeric($value)) {
            $value = strlen($value);
        }
        return $value >= $min && $value <= $max;
    }	
	
	public static function alpha($value) {
		return preg_match('/^[a-z_]+$/i', $value);
	}
	
	public static function matches($value, $field) {
		if (!isset($field)) {
			return false;
		}
		return $value !== $field;
	}
	
	public static function numeric($value) {
		return preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $value);
	}
}

?>